package org.itboys.mobile.controller.site;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mongo.JoinPartner;
import org.itboys.mobile.service.mongo.site.JoinSitePartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2018/1/17
 * 描述：加盟网_合伙人
 */
@Controller
@RequestMapping("/join/site/partner")
public class JoinSitePartnerController extends BaseController{
    @Autowired
    private JoinSitePartnerService partnerService;
    @RequestMapping("/save")
    public void save(HttpServletRequest request,
                     HttpServletResponse response,
                     @RequestParam(value="nickName",required=true)String nickName,
                     @RequestParam(value="phone",required=true)String phone,
                     @RequestParam(value="sex",required=true)String sex,
                     @RequestParam(value="idCard",required=true)String idCard,
                     @RequestParam(value="type",required=true)Integer type,
                     @RequestParam(value="partnerRole",required=true)String partnerRole,

                     @RequestParam(value="provinceId",required=false)Long provinceId,
                     @RequestParam(value="provinceName",required=false)String provinceName,
                     @RequestParam(value="cityId",required=false)Long cityId,
                     @RequestParam(value="cityName",required=false)String cityName,
                     @RequestParam(value="districtId",required=false)Long districtId,
                     @RequestParam(value="districtName",required=false)String districtName
    ){
        try {
            //codeService.checkValidateCode(phone,code);
            partnerService.save(new JoinPartner(nickName,sex,idCard,phone,type,partnerRole,provinceId,provinceName,cityId,cityName,districtId,districtName));
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));

        } catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/join/site/partner/save------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));;
        }

    }

}
